home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / dejagnu.lha / dejagnu-1.0.1 / tcl / tests / append.test < prev    next >
Text File  |  1992-11-06  |  3KB  |  105 lines

  1. # Commands covered:  append lappend
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright 1991 Regents of the University of California
  8. # Permission to use, copy, modify, and distribute this
  9. # software and its documentation for any purpose and without
  10. # fee is hereby granted, provided that this copyright notice
  11. # appears in all copies.  The University of California makes no
  12. # representations about the suitability of this software for any
  13. # purpose.  It is provided "as is" without express or implied
  14. # warranty.
  15. #
  16. # $Header: /user6/ouster/tcl/tests/RCS/append.test,v 1.4 92/05/07 09:24:32 ouster Exp $ (Berkeley)
  17.  
  18. if {[string compare test [info procs test]] == 1} then {source defs}
  19.  
  20. catch {unset x}
  21. test append-1.1 {append command} {
  22.     catch {unset x}
  23.     list [append x 1 2 abc "long string"] $x
  24. } {{12abclong string} {12abclong string}}
  25. test append-1.2 {append command} {
  26.     set x ""
  27.     list [append x first] [append x second] [append x third] $x
  28. } {first firstsecond firstsecondthird firstsecondthird}
  29.  
  30. test append-2.1 {long appends} {
  31.     set x ""
  32.     for {set i 0} {$i < 1000} {set i [expr $i+1]} {
  33.     append x "foobar "
  34.     }
  35.     set y "foobar"
  36.     set y "$y $y $y $y $y $y $y $y $y $y"
  37.     set y "$y $y $y $y $y $y $y $y $y $y"
  38.     set y "$y $y $y $y $y $y $y $y $y $y "
  39.     expr {$x == $y}
  40. } 1
  41.  
  42. test append-3.1 {append errors} {
  43.     list [catch {append} msg] $msg
  44. } {1 {wrong # args: should be "append varName value ?value ...?"}}
  45. test append-3.2 {append errors} {
  46.     list [catch {append x} msg] $msg
  47. } {1 {wrong # args: should be "append varName value ?value ...?"}}
  48. test append-3.3 {append errors} {
  49.     set x ""
  50.     list [catch {append x(0) 44} msg] $msg
  51. } {1 {can't set "x(0)": variable isn't array}}
  52.  
  53. test append-4.1 {lappend command} {
  54.     catch {unset x}
  55.     list [lappend x 1 2 abc "long string"] $x
  56. } {{1 2 abc {long string}} {1 2 abc {long string}}}
  57. test append-4.2 {lappend command} {
  58.     set x ""
  59.     list [lappend x first] [lappend x second] [lappend x third] $x
  60. } {first {first second} {first second third} {first second third}}
  61. test append-4.3 {lappend command} {
  62.     proc foo {} {
  63.     global x
  64.     set x old
  65.     unset x
  66.     lappend x new
  67.     }
  68.     set result [foo]
  69.     rename foo {}
  70.     set result
  71. } {new}
  72.  
  73.  
  74. proc check {var size} {
  75.     set l [llength $var]
  76.     if {$l != $size} {
  77.     return "length mismatch: should have been $size, was $l"
  78.     }
  79.     for {set i 0} {$i < $size} {set i [expr $i+1]} {
  80.     set j [lindex $var $i]
  81.     if {$j != "item $i"} {
  82.         return "element $i should have been \"item $i\", was \"$j\"
  83.     }
  84.     }
  85.     return ok
  86. }
  87. test append-5.1 {long lappends} {
  88.     set x ""
  89.     for {set i 0} {$i < 300} {set i [expr $i+1]} {
  90.     lappend x "item $i"
  91.     }
  92.     check $x 300
  93. } ok
  94.  
  95. test append-6.1 {lappend errors} {
  96.     list [catch {lappend} msg] $msg
  97. } {1 {wrong # args: should be "lappend varName value ?value ...?"}}
  98. test append-6.2 {lappend errors} {
  99.     list [catch {lappend x} msg] $msg
  100. } {1 {wrong # args: should be "lappend varName value ?value ...?"}}
  101. test append-6.3 {lappend errors} {
  102.     set x ""
  103.     list [catch {lappend x(0) 44} msg] $msg
  104. } {1 {can't set "x(0)": variable isn't array}}
  105.